package com.zhiying.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.plugins.Page;
import com.zhiying.config.StatusEnum;
import com.zhiying.domain.OS_Product;
import com.zhiying.mybatis.ProductMapper;
import com.zhiying.page.PageInfo;
import com.zhiying.service.ProductService;

@Transactional
@Service
@Component
public class ProductServiceImpl  implements ProductService{

	@Autowired
	private ProductMapper productMapper;
	@Override
	public List<OS_Product> SelectAllinfo(PageInfo pageInfo, String search) {
		// TODO Auto-generated method stub
		Page<OS_Product> page = new Page<>(pageInfo.getCurrent(), pageInfo.getLimit());
		List<OS_Product> productlist = productMapper.SelectAllinfo(pageInfo, search, page);
		pageInfo.setTotal(SelectAllCount(search));
		return productlist;
	}

	@Override
	public int UpdateshowInShelve(OS_Product product) {
		// TODO Auto-generated method stub
		int showInShelve=productMapper.SelectshowInShelveByid(product.getProductId());
		System.out.println(showInShelve);
		if(showInShelve==StatusEnum.SHELVE.getStatus()) {
			OS_Product updateProduct=new OS_Product();
			updateProduct.setProductId(product.getProductId());
			updateProduct.setShowInShelve(0);
			return productMapper.UpdateshowInShelve(updateProduct);
		}else if(showInShelve==StatusEnum.OFF_SHELVE.getStatus()){
			OS_Product updateProduct=new OS_Product();
			updateProduct.setProductId(product.getProductId());
			updateProduct.setShowInShelve(1);
			return productMapper.UpdateshowInShelve(updateProduct);
		}
		return 0;
	}

	@Override
	public int SelectshowInShelveByid(Long id) {
		// TODO Auto-generated method stub
		return productMapper.SelectshowInShelveByid(id);
	}

	@Override
	public int SelectAllCount(String Search) {
		// TODO Auto-generated method stub
		return productMapper.SelectAllCount(Search);
	}

	@Override
	public OS_Product SelectinfoByproductNumber(Long productNumber) {
		// TODO Auto-generated method stub
		return productMapper.SelectinfoByproductNumber(productNumber);
	}

	@Override
	public int DeletinfoById(Long productId) {
		// TODO Auto-generated method stub
		return productMapper.DeletinfoById(productId);
	}

	@Override
	public int UpdateinfoById(OS_Product product) {
		// TODO Auto-generated method stub
		return productMapper.UpdateinfoById(product);
	}

	@Override
	public int InsertInfo(OS_Product product) {
		// TODO Auto-generated method stub
		return productMapper.InsertInfo(product);
	}

}
